﻿
-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Mrinmoy Das>
-- Create date: <11/04/2011>
-- Description:	<sp_User_GetByCriteria>
-- =============================================
IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'sp_User_GetByCriteria')
	BEGIN
		DROP  Procedure  sp_User_GetByCriteria
	END

GO

CREATE PROCEDURE sp_User_GetByCriteria 
	-- Add the parameters for the stored procedure here
	(
				@UserLoginID varchar(50) = NULL,
				@UserPassword varchar(50) = NULL,
				@UserFirstName varchar(50) = NULL,
				@UserLastName varchar(50) = NULL,
				@UserPrimaryEmailID varchar(150) = NULL,
				@UserVerificationCode varchar(50) = NULL,
				@UserIsVarified bit = false,
				@Sys_DateOfCreation datetime = NULL,
				@Sys_DateOfModification datetime = NULL,
				@Sys_CreatedByID varchar(50)= NULL,
				@Sys_ModifiedByID varchar(50) = NULL,
				@Sys_DeleteType int = NULL,
				@Sys_IsDeleted int = 0,
				@Sys_OrganizationID int = -1,
				@Sys_InitialPrimaryKeys varchar(100)= NULL,
				@Sys_WorkstationName varchar(50)= NULL

	)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT OFF;

	SELECT	[UserKey],
			[UserLoginID],
			[UserPassword],
			[UserFirstName],
			[UserLastName],
			[UserPrimaryEmailID],
			[UserVerificationCode],
			[UserIsVarified],
			[Sys_DateOfCreation],
			[Sys_DateOfModification],
			[Sys_CreatedByID],
			[Sys_ModifiedByID],
			[Sys_DeleteType],
			[Sys_IsDeleted],
			[Sys_OrganizationID],
			[Sys_InitialPrimaryKeys],
			[Sys_WorkstationName]
	FROM	[User]
	WHERE		
		(
			(@UserLoginID IS NULL OR [UserLoginID] = @UserLoginID) AND
			(@UserPassword IS NULL OR [UserPassword] = @UserPassword) AND
			(@UserFirstName IS NULL OR [UserFirstName] = @UserFirstName) AND
			(@UserLastName IS NULL OR [UserLastName] = @UserLastName) AND
			(@UserPrimaryEmailID IS NULL OR [UserPrimaryEmailID] = @UserPrimaryEmailID) AND
			(@UserVerificationCode IS NULL OR [UserVerificationCode] = @UserVerificationCode) AND
			(@UserIsVarified IS NULL OR [UserIsVarified] = @UserIsVarified) AND
			(@Sys_DateOfCreation IS NULL OR [Sys_DateOfCreation] = @Sys_DateOfCreation) AND
			(@Sys_DateOfModification IS NULL OR [Sys_DateOfModification] = @Sys_DateOfModification) AND
			(@Sys_CreatedByID IS NULL OR [Sys_CreatedByID] = @Sys_CreatedByID) AND
			(@Sys_ModifiedByID IS NULL OR [Sys_ModifiedByID] = @Sys_ModifiedByID) AND
			(@Sys_DeleteType IS NULL OR [Sys_DeleteType] = @Sys_DeleteType) AND
			(@Sys_IsDeleted IS NULL OR [Sys_IsDeleted] = @Sys_IsDeleted) AND
			(@Sys_OrganizationID IS NULL OR [Sys_OrganizationID] = @Sys_OrganizationID) AND
			(@Sys_InitialPrimaryKeys IS NULL OR [Sys_InitialPrimaryKeys] = @Sys_InitialPrimaryKeys) AND
			(@Sys_WorkstationName IS NULL OR [Sys_WorkstationName] = @Sys_WorkstationName)
		);
END
GO
 